package com.yeyv.net.Web.Control;

import com.yeyv.net.UsefulEntity.Resp;
import com.yeyv.net.Web.Utils.BaseYvEntity;
import lombok.Data;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Log4j2
@RestController
@RequestMapping("/verify")
public class VerifyController {

    @Data
    @ToString
    public static class VerifyRequest {
        public String from;

        public String to;

        public String token;
    }

    @Data
    @ToString
    public static class VerifyEntity{
        // SUCCESS ; REDIRECT ; ERROR ;
        public String code = "SUCCESS";

        public String from = "/verify/success";

        public String to = "/verify/error";

        public BaseYvEntity result = null;

        public void parseRequest(VerifyRequest request) {
            this.setTo(request.getTo());
            this.setFrom(request.getFrom());
        }
    }

    /**
     *
     */
    @PostMapping("/simple")
    public Resp<VerifyEntity> simple(@RequestBody VerifyRequest verifyRequest) {
        log.info("VERIFY =>"+verifyRequest.toString());
        var result = new VerifyEntity();
        // TODO : 验证代码
        // ...
        // TODO : 验证失败返回
        // ...
        // 验证成功返回
        result.parseRequest(verifyRequest);
        log.info("VERIFY RESULT => " + result);
        return Resp.success(result);
    }

}
